package adb_read

import (
	"iron_man_comm/src/utils"
	"os"
)

/**
 * @brief:	读取文件
 */
func ReadFile(ip string, filePath string) (string, error) {
	if "127.0.0.1" == ip {
		//本地读取
		return readLocal(filePath)
	} else {
		//远程线读
		return readAdb(filePath)
	}
}

func readLocal(filePath string) (string, error) {
	bytes, err := os.ReadFile(filePath)
	if err != nil {
		return "", err
	}
	return string(bytes), nil
}

func readAdb(filePath string) (string, error) {
	_, err := utils.RunAdbCommand("pull", filePath, "./")
	if err != nil {
		return "", err
	}
	return readLocal("version.txt")
}
